<template>
  <div class="icons">
    <swiper>
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon"
             v-for=" item of page" :key="item.id">
          <div class="icon-img">
            <img class="icon-imgcontent" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{ item.title }}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      iconList: [{
        id: '009',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: 'PHP资料'
      }, {
        id: '008',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: 'Web前端资料'
      }, {
        id: '001',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: '服务器/运维'
      }, {
        id: '002',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: 'UI/设计'
      }, {
        id: '003',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: 'Java'
      }, {
        id: '004',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: '算法编程'
      }, {
        id: '005',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: '全民诵读'
      }, {
        id: '006',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: '前沿攻略'
      }, {
        id: '007',
        imgUrl: 'http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20215/bdbdf2d8bbc533595440c74c7bd22af4.png',
        title: '全民诵读'
      }]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 4)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import "~styles/varibles.styl"
// 注意当滑动时两层item时，下面的不滑动，那么我们需要让icons下的swiper-container高度跟icons高度一样
.icons >>>.swiper-container
  height :0
  padding-bottom :25%
.icons
  margin-top :.1rem
  .icon
    position :relative
    overflow :hidden
    float :left
    width :25%
    padding-bottom :25%
    height :0
    .icon-desc
      position absolute
      left :0
      right :0
      bottom :0
      line-height :.44rem
      color :$darkTextColor
      text-align :center
      overflow :hidden
      white-space :nowrap
      text-overflow: ellipsis
    .icon-img
      position :absolute
      top :0
      left :0
      right :0
      bottom :.44rem
      box-sizing :border-box
      -moz-box-sizing:border-box
      -webkit-box-sizing:border-box
      padding :.1rem
      .icon-imgcontent
        height :100%
        display :block
        margin :0 auto

</style>
